package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/*
* 通过此对象演示切面中各种通知（Advice）方法的执行
* */
@Aspect
@Component
public class SysTimeAspect {
    @Pointcut("bean(categoryServiceImpl)")
    public void doTime(){}

    @Before("doTime()")
    public void doBefore(){
        System.out.println("@Before");
    }
    @After("doTime()")
    public void doAfter(){
        System.out.println("@After");
    }
    @AfterReturning("doTime()")
    public void doAfterReturning(){
        System.out.println("@doAfterReturning");
    }

    @AfterThrowing("doTime()")
    public void doAfterThrowing(){
        System.out.println("@AfterThrowing");
    }

    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint jp)throws Throwable{
        System.out.println("@Around.before");
        try{
            Object result=jp.proceed();
            System.out.println("doAround.after");
            return result;
        }catch(Throwable e){
            System.out.println(e.getMessage());
            throw e;
        }
    }
}
